package com.ruoyi.demo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.demo.domain.DemoShop;
import com.ruoyi.demo.service.IDemoShopService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品Controller
 * 
 * @author ruoyi
 * @date 2025-10-14
 */
@RestController
@RequestMapping("/demo/shop")
public class DemoShopController extends BaseController
{
    @Autowired
    private IDemoShopService demoShopService;

    /**
     * 查询商品列表
     */
    @PreAuthorize("@ss.hasPermi('demo:shop:list')")
    @GetMapping("/list")
    public TableDataInfo list(DemoShop demoShop)
    {
        startPage();
        List<DemoShop> list = demoShopService.selectDemoShopList(demoShop);
        return getDataTable(list);
    }

    /**
     * 导出商品列表
     */
    @PreAuthorize("@ss.hasPermi('demo:shop:export')")
    @Log(title = "商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DemoShop demoShop)
    {
        List<DemoShop> list = demoShopService.selectDemoShopList(demoShop);
        ExcelUtil<DemoShop> util = new ExcelUtil<DemoShop>(DemoShop.class);
        util.exportExcel(response, list, "商品数据");
    }

    /**
     * 获取商品详细信息
     */
    @PreAuthorize("@ss.hasPermi('demo:shop:query')")
    @GetMapping(value = "/{shopId}")
    public AjaxResult getInfo(@PathVariable("shopId") Long shopId)
    {
        return success(demoShopService.selectDemoShopByShopId(shopId));
    }

    /**
     * 新增商品
     */
    @PreAuthorize("@ss.hasPermi('demo:shop:add')")
    @Log(title = "商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DemoShop demoShop)
    {
        return toAjax(demoShopService.insertDemoShop(demoShop));
    }

    /**
     * 修改商品
     */
    @PreAuthorize("@ss.hasPermi('demo:shop:edit')")
    @Log(title = "商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DemoShop demoShop)
    {
        return toAjax(demoShopService.updateDemoShop(demoShop));
    }

    /**
     * 删除商品
     */
    @PreAuthorize("@ss.hasPermi('demo:shop:remove')")
    @Log(title = "商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{shopIds}")
    public AjaxResult remove(@PathVariable Long[] shopIds)
    {
        return toAjax(demoShopService.deleteDemoShopByShopIds(shopIds));
    }
}
